package gamecenter.gc.controller;

import gamecenter.gc.bean.Game;
import gamecenter.gc.bean.Game_Developer;
import gamecenter.gc.service.Game_Developer_Service;
import gamecenter.gc.service.Game_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Game_Developer_Controller {
    @Autowired
    private Game_Developer_Service game_developer_service;
    @Autowired
    private Game_Service game_service;

    @RequestMapping(value = "get_Cer_game_Developer", method = RequestMethod.GET)
    public Game_Developer get_Cer_game_Developer_From_Name(String name) {
        return game_developer_service.get_Game_Developer_From_Name(name);
    }

    @RequestMapping(value = "add_Game", method = RequestMethod.POST)
    public boolean add_Game(@RequestBody Game game) {
        Game g = game_service.get_Cer_Game_From_Name(game.getName());
        if (g != null) {
            return false;
        }
        Game_Developer game_developer = game_developer_service.get_Game_Developer_From_Name(game.getGame_Developer());
        if (game_developer == null)
            return false;
        game_service.add_Game(game);
        return true;
    }
}
